package com.njtoyo.taxi.admin.rest.controller;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.njtoyo.taxi.admin.aop.PassToken;
import com.njtoyo.taxi.admin.aop.SensitiveOperation;
import com.njtoyo.taxi.admin.library.Const;
import com.njtoyo.taxi.admin.library.common.SensitiveOperationHelper;
import com.njtoyo.taxi.admin.library.sms.YunpianSmsClient;
import com.njtoyo.taxi.admin.mapper.secondary.mapper.AdminUserMapper;
import com.taxi.entity.common.RestResult;
import com.njtoyo.taxi.entity.backend.AdminUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.net.InetAddress;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author Dell
 * @Date 2021/6/1 14:53
 */
@RestController
@RequestMapping("/general")
@Api(tags = "通用管理接口", description = "通用管理接口")
@RequiredArgsConstructor
public class GeneralController {
    private final AdminUserMapper adminUserMapper;
    private final SensitiveOperationHelper sensitiveOperationHelper;
    private final Client client;
    private final YunpianSmsClient yunpianSmsClient;

    @GetMapping("/alive")
    @SneakyThrows
    @ApiOperation(value = "检查服务器是否存活", notes = "检查服务器是否存活")
    @DS(Const.SECONDARY_DS)
    @PassToken
    public RestResult alive(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser){
        System.out.println(adminUser);
        InetAddress host = InetAddress.getLocalHost();
        Map<String, Object> result = new HashMap<>();
        result.put("alive", host.getHostName());
        result.put("timestamp", System.currentTimeMillis());
//        result.put("admin",adminUserMapper.selectByAccount("kiyoma"));
        return RestResult.success(result);
    }

    @GetMapping("test_sensitive_operation")
    @SensitiveOperation(name = "order_refund")
    public RestResult testSensitiveOperation() {
        return RestResult.success();
    }


    @GetMapping("sms")
    @PassToken
    public void testSms() throws Exception {
        String shortUrl = yunpianSmsClient.addShortUrl("http://taxi-uat.jjtoyo.com/driver_h5/sign-up/update?sign=12345456");
        System.out.println(shortUrl);
    }
}
